package com.clms.statistics.service.impl;

import com.clms.common.R;
import com.clms.statistics.mapper.ULogMapper;
import com.clms.statistics.service.ULogService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: clms-third
 * @description:
 * @author: 许鹏
 * @create: 2021-07-26 11:41
 **/
@Service
@ApiModel(value = "操作记录的service")
public class ULogServiceImpl implements ULogService {
    @Resource
    private ULogMapper uLogMapper;

    @Override
    @ApiModelProperty(value = "操作记录的实现")
    public R Ulog(String years) {
        //拿到所有已操作的业务类型（0-其他，1-新增，2-修改，3-删除）
        List<Map> list = uLogMapper.Ulog(years);
        System.out.println(list);
        List<String> datax = new ArrayList();
        List<Integer> type = new ArrayList();

        //用来存放business_type=1的数据
        List count1 = new ArrayList<>();
        List count2 = new ArrayList<>();
        List count3 = new ArrayList<>();

        //用来存放business_type=1的数据
        List<Map> tt1 = new ArrayList<>();
        List<Map> tt2 = new ArrayList<>();
        List<Map> tt3 = new ArrayList<>();

        //循环遍历分别拿出Key和value
        for (Map map : list) {
            datax.add(String.valueOf(map.get("oper_time")));
            type.add(Integer.valueOf(map.get("business_type").toString()));
            if (map.get("business_type").equals(1)) {
                tt1.add(map);
                for (Map map1 : tt1) {
                    count1.add(Integer.valueOf(map1.get("count").toString()));
                }
            }
            if (map.get("business_type").equals(2)) {
                tt2.add(map);
                for (Map map1 : tt2) {
                    count2.add(Integer.valueOf(map1.get("count").toString()));
                }
            }
            if (map.get("business_type").equals(3)) {
                tt3.add(map);
                for (Map map1 : tt3) {
                    count3.add(Integer.valueOf(map1.get("count").toString()));
                }
            }
        }
        System.out.println(datax);
        //生成一个新的数组xindate用来存储hedate去除重复后的数组
        List newdatax = new ArrayList();
        for (int i = 0; i < datax.size(); i++) {
            if (!newdatax.contains(datax.get(i))) {
                newdatax.add(datax.get(i));
            }
        }

        Map logdata = new HashMap();
        logdata.put("newdatax", newdatax);
        logdata.put("type", type);
        logdata.put("count1", count1);
        logdata.put("count2", count2);
        logdata.put("count3", count3);

        return R.ok().put("logdata", logdata);
    }
}
